
function selectEmployee(emp_id){
	var url = '/storage/admin/pages/employee.do?method=selectEmployee&d=' + new Date();
	url = url + '&emp_id='+emp_id;
	
	$.getJSON(url, {}, function(data){
		var emp_id = document.getElementById('emp_id');
		var emp_cid = document.getElementById('emp_cid');
		var emp_name = document.getElementById('emp_name');
		var emp_job = document.getElementById('emp_job');
		var emp_state = document.getElementById('emp_state');
		var emp_phone = document.getElementById('emp_phone');
		var emp_address = document.getElementById('emp_address');
		var emp_info = document.getElementById('emp_info');
		var is_opr = document.getElementById('is_opr');

		setTimeout(function (){
			emp_id.value = data[0][0];
			emp_name.value = data[0][1];
			emp_cid.value = data[0][2];
			emp_phone.value = data[0][5];
			emp_address.value = data[0][6];
			emp_info.value = data[0][9];
			
			emp_job.value = data[0][7];
			emp_state.value = data[0][4];
			data[0][8]==1?is_opr.checked=true:is_opr.checked=false;
		},500);
	});
};
function saveOrUpdate(){
	var emp_id_val = document.getElementById('emp_id').value;
	var emp_cid = document.getElementById('emp_cid').value;
	var emp_name = document.getElementById('emp_name').value;
	var emp_job = document.getElementById('emp_job').value;
	var emp_state = document.getElementById('emp_state').value;
	
	var isFull = ''!=emp_cid&&''!=emp_name&&''!=emp_state;
	
	if(isFull){
		emp_id_val==''?save():update();
	}else{
		alert('必要信息不完整');
	}
};
function save(){
	var emp_cid = escape(escape(document.getElementById('emp_cid').value));
	var emp_name = escape(escape(document.getElementById('emp_name').value));
	var emp_job = escape(escape(document.getElementById('emp_job').value));
	var emp_state = escape(escape(document.getElementById('emp_state').value));
	var emp_phone = escape(escape(document.getElementById('emp_phone').value));
	var emp_address = escape(escape(document.getElementById('emp_address').value));
	var emp_info = escape(escape(document.getElementById('emp_info').value));
	var is_opr = escape(escape(document.getElementById('is_opr').checked?1:0));
	
	var url = '/storage/admin/pages/employee.do?method=create&d=' + new Date();
	url = url + '&emp_cid='+emp_cid;
	url = url + '&emp_name='+emp_name;
	url = url + '&emp_job='+emp_job;
	url = url + '&emp_state='+emp_state;
	url = url + '&emp_phone='+emp_phone;
	url = url + '&emp_address='+emp_address;
	url = url + '&emp_info='+emp_info;
	url = url + '&is_opr='+is_opr;
	
	$.getJSON(url, {}, function(data){
		if(data=="true"){
			alert("保存成功");
			window.close();
		}else{
			alert("证件号码已经使用过了");
		}
	});
};
function update(){
	var emp_id = escape(escape(document.getElementById('emp_id').value));
	var emp_cid = escape(escape(document.getElementById('emp_cid').value));
	var emp_name = escape(escape(document.getElementById('emp_name').value));
	var emp_job = escape(escape(document.getElementById('emp_job').value));
	var emp_state = escape(escape(document.getElementById('emp_state').value));
	var emp_phone = escape(escape(document.getElementById('emp_phone').value));
	var emp_address = escape(escape(document.getElementById('emp_address').value));
	var emp_info = escape(escape(document.getElementById('emp_info').value));
	var is_opr = escape(escape(document.getElementById('is_opr').checked?1:0));

	var url = '/storage/admin/pages/employee.do?method=update&d=' + new Date();
	url = url + '&emp_id='+emp_id;
	url = url + '&emp_cid='+emp_cid;
	url = url + '&emp_name='+emp_name;
	url = url + '&emp_job='+emp_job;
	url = url + '&emp_state='+emp_state;
	url = url + '&emp_phone='+emp_phone;
	url = url + '&emp_address='+emp_address;
	url = url + '&emp_info='+emp_info;
	url = url + '&is_opr='+is_opr;
	
	$.getJSON(url, {}, function(data){
		if(data=="true"){
			alert("更新成功");
			window.close();
		}else{
			alert("更新失败");
		}
	});
};